package com.mew.chess.core.common.handler;

import com.mew.common.dc.redis.GameRoomRedisService;
import com.mew.common.dc.redis.UserProfileRedisService;
import com.mew.common.entity.config.Game;
import com.mew.common.rest.bo.MaxBonusBO;
import com.mew.common.rest.bo.MaxBonusManager;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class MaxBonusService {

    @Autowired
    private UserProfileRedisService userProfileRedisService;
    @Autowired
    private GameRoomRedisService gameRoomRedisService;
    @Autowired
    private StrategyConfig strategyConfig;

    public void addMaxBonus(long userId, int gameId, long payment, int betTimes){
        if (betTimes < 50){
            return;
        }

        Game game = gameRoomRedisService.getRedisGame(gameId);
        if (game == null){
            return;
        }

        long max;
        int  mul;
        if ("QMCS".equals(game.getGameVfx())){
            max = strategyConfig.qumoGoldMax();
            mul = strategyConfig.getQumoMul();
        }else {
            max = strategyConfig.fishGoldMax();
            mul = strategyConfig.getFishMul();
        }

        if (payment >= max && betTimes >= mul){
            MaxBonusBO maxBonusBO = MaxBonusBO.builder()
                    .un(userProfileRedisService.getRedisUserById(userId).getNickname())
                    .gn(gameRoomRedisService.getRedisGame(gameId).getForeignLag())
                    .num(payment)
                    .build();
            MaxBonusManager.getInstance().add(maxBonusBO);
        }

    }
}
